package com.xzzz.expand.gateway.dr;

import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.filter.factory.GatewayFilterFactory;
import org.springframework.cloud.gateway.handler.predicate.RoutePredicateFactory;
import org.springframework.cloud.gateway.route.RouteDefinitionLocator;
import org.springframework.cloud.gateway.route.RouteDefinitionWriter;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.context.annotation.Bean;

import java.util.List;

/**
 * @author xzzz
 */
public class GatewayDynamicRouteConfiguration {

    /**
     * 路由API
     * @param routeDefinitionLocator
     * @param globalFilters
     * @param gatewayFilters
     * @param routePredicates
     * @param routeDefinitionWriter
     * @param routeLocator
     * @return
     */
    @Bean
    public GatewayController gatewayController(RouteDefinitionLocator routeDefinitionLocator,
                                               List<GlobalFilter> globalFilters,
                                               List<GatewayFilterFactory> gatewayFilters,
                                               List<RoutePredicateFactory> routePredicates,
                                               RouteDefinitionWriter routeDefinitionWriter,
                                               RouteLocator routeLocator) {
        return new GatewayController(routeDefinitionLocator,
                globalFilters,
                gatewayFilters,
                routePredicates,
                routeDefinitionWriter,
                routeLocator);
    }

    /**
     * 路由工具类
     * @param gatewayFilters
     * @param routePredicates
     * @return
     */
    @Bean
    public RouteUtil routeUtil(List<GatewayFilterFactory> gatewayFilters, List<RoutePredicateFactory> routePredicates) {
        return new RouteUtil(gatewayFilters, routePredicates);
    }
}
